package com.lbs.jiepiaisi;
import android.os.Build;
import android.os.Handler;
import android.os.StrictMode;
import android.os.Bundle;
import android.Manifest;
import com.lbs.jiepiaisi.activity.OpenFragmentActivity;
import com.lbs.jiepiaisi.base.BasePermissionActivity;
import com.lbs.jiepiaisi.utils.IntentUtil;
import com.lbs.jiepiaisi.utils.ToastUtil;

/**
 * 时间：2017/8/14
 * 作用：主函数入口
 */
public class MainActivity extends BasePermissionActivity {

    Handler handler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        //requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        //7.0相机权限设置
        //（不设置的话 7.0以上一调用拍照功能就崩溃了）
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
            StrictMode.setVmPolicy(builder.build());
        }
        //权限处理
        requestPermissions(this, new String[]{
                        Manifest.permission.CAMERA,
                        Manifest.permission.ACCESS_FINE_LOCATION,//位置
                        Manifest.permission.WRITE_EXTERNAL_STORAGE,      //SD卡读写
                        Manifest.permission.READ_EXTERNAL_STORAGE,       //SD卡读写
                        Manifest.permission.WAKE_LOCK,//允许程序在手机屏幕关闭后后台进程仍然运行
                        Manifest.permission.READ_PHONE_STATE//读写手机状态和身份
                        //Manifest.permission.RECORD_AUDIO//录制声音通过手机或耳机的麦克
                        //Manifest.permission.WRITE_SETTINGS,//允许读写系统设置顶
                },
                new RequestPermissionCallBack() {
                    @Override
                    public void granted() {
                        try {
                            handler.postDelayed(() -> {
                                IntentUtil.gotoActivity(MainActivity.this, OpenFragmentActivity.class,true);
                                overridePendingTransition(R.anim.anim_fade_in,R.anim.anim_fade_out);
                            },2000);
                        }catch (Exception e){
                            e.printStackTrace();
                        }
                    }
                    @Override
                    public void denied() {
                        ToastUtil.show("获取权限失败，功能受到影响");
                        finish();
                    }
                });
        }
}
